# -*- coding: utf-8 -*-

import logging
from http import HTTPStatus

from django import forms
from django.core.exceptions import ValidationError


class PostForm(forms.Form):
    username = forms.CharField(label='用户名', min_length=4, max_length=128,
                               error_messages={HTTPStatus.INTERNAL_SERVER_ERROR: '用户名无效'})
    password = forms.CharField(widget=forms.PasswordInput, label='密码')

    def clean(self):
        cleaned_data = super().clean()
        username = cleaned_data.get('username')
        password = cleaned_data.get('password')

        username_list = list()
        if username not in username_list:
            raise ValidationError('用户不存在', code=HTTPStatus.INTERNAL_SERVER_ERROR)
